<?php
namespace app\admin\controller;
use app\common\BaseController;
use think\Db;
use app\admin\model\Good as GoodModel;
class Good extends BaseController
{
	public function index(){
		
		
		return view('index');
	}

	public function addGood(GoodModel $good){
		
		if(request()->isPost()){
			return $good->add();
		}
		$parent_id = Db::name('CateGory')->field('category_name,parent_id,id')->select();

		$parent_id = generateTree($parent_id);
		return view('add',['CateGory'=>$parent_id]);
	}

	public function getInfo(GoodModel $good){
		$page = input('page');
    	$limit = input('limit');
    	$good = $good->Aselect($page,$limit);
    	return $good;
	}
	public function edit($id,GoodModel $good){
		if(request()->isAjax() && request()->isPost()){
			return $good->updateGood();
		}
		$good = GoodModel::where('id',$id)->find();
		$parent_id = Db::name('CateGory')->field('category_name,parent_id,id')->select();

		$parent_id = generateTree($parent_id);
		return view('edit',['good'=>$good,'CateGory'=>$parent_id]);
	}
	public function del($id,GoodModel $good){
		if(request()->isAjax() && request()->isGet()){ 
            GoodModel::destroy($id);
            return 'success';
        }
	}
}